//
//  AppDelegate.m
//  暴走段子_王桂敏
//
//  Created by 王桂敏 on 15/6/1.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "AppDelegate.h"
#import "DuanziViewController.h"
#import "RootViewController.h"
#import "CustomizedNavigationController.h"
#import "MMDrawerController.h"
#import "MMExampleDrawerVisualStateManager.h"
#import "ScrollViewController.h"
#import "UMSocial.h"
#import "Define.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
- (void)dealloc{
    [_window release];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
#pragma mark -laze loading -


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor blackColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sliderValueChange:) name:kLightChange object:nil];
    [self.window makeKeyAndVisible];
//    CustumTabBarController *custumTBC = [[CustumTabBarController alloc] init];
//    self.window.rootViewController = custumTBC;

    [UMSocialData setAppKey:@"557bfe6b67e58e83b0004b5e"];

    [NSThread sleepForTimeInterval:1];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blackColor]}];

    RootViewController *leftVC = [[RootViewController alloc] init];
    CustomizedNavigationController *leftNaviC = [[CustomizedNavigationController alloc] initWithRootViewController:leftVC];
    [leftVC release];

    DuanziViewController *duanziVC = [[DuanziViewController alloc] init];
    CustomizedNavigationController *duanziNaviC = [[CustomizedNavigationController alloc] initWithRootViewController:duanziVC];
    [duanziVC release];
    
    //抽屉管理 第三方
    //该第三方既可以只实现打开左侧栏也可以实现打开右侧栏,还可以同时都实现
//    MMDrawerController *rooVC = [[MMDrawerController alloc] initWithCenterViewController:navigationVC leftDrawerViewController:leftNavigationVC rightDrawerViewController:rightNavigationVC];

    //只实现打开左侧栏
        MMDrawerController *rooVCLeft = [[MMDrawerController alloc] initWithCenterViewController:duanziNaviC leftDrawerViewController:leftNaviC];
    [duanziNaviC release];
    [leftNaviC release];
    //只实现打开右侧栏
    //MMDrawerController *rooVCRight = [[MMDrawerController alloc] initWithCenterViewController:navigationVC rightDrawerViewController:thirdVC];

    //判断是不是第一次启动应用
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        NSLog(@"第一次启动");
        //如果是第一次启动的话,使用scrollViewController (用户引导页面) 作为根视图
        ScrollViewController *scrollViewController = [[ScrollViewController alloc]init];
        self.window.rootViewController = scrollViewController;
        [scrollViewController release];
    }
    else
    {

        self.window.rootViewController = rooVCLeft;
    }


    //指定window的根视图


    //测了门的宽度
    [rooVCLeft setMaximumLeftDrawerWidth:170];
    //设置侧拉门开与关的动画
    [rooVCLeft setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [rooVCLeft setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    //侧开内容展示效果
    //设置向左滑动打开右侧栏
//    [[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:MMDrawerAnimationTypeParallax];
    //设置向右滑动打开左侧栏
    [[MMExampleDrawerVisualStateManager sharedManager] setLeftDrawerAnimationType:MMDrawerAnimationTypeSwingingDoor];

    //
    [rooVCLeft setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
        MMDrawerControllerDrawerVisualStateBlock block;
        block = [[MMExampleDrawerVisualStateManager sharedManager]
                 drawerVisualStateBlockForDrawerSide:drawerSide];
        if(block){
            block(drawerController, drawerSide, percentVisible);
        }
    }];

    [rooVCLeft release];
    return YES;
}

- (void)sliderValueChange:(NSNotification *)notification{
    NSDictionary *dic = notification.userInfo;
    CGFloat value = [dic[@"value"] floatValue];
    self.window.alpha = value;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
